#include <iostream>
#include <array>
#include <list>
#include <string>
#include "../src/SSP_College.hpp"
#include <signal.h>
#include <unistd.h>

std::array<std::string,2> cameraIPList={"192.168.1.104","192.168.1.105"};
SSPCollege* ssp_main;

void Handle_H264Data(const char*,std::size_t size,unsigned long frameID,std::any& userData)
{
  std::cout
    <<"Camera "<<std::any_cast<int>(userData)
    <<" new data size "<<size
    <<" frame id "<<frameID
    <<std::endl;
}

void Handle_SIGINT(int)
{

}

int main()
{
  std::cout<<"Camera boot ... "<<std::endl;
  std::vector<std::pair<std::string,std::any>> dataList;
  dataList.reserve(cameraIPList.size());
  int counter=0;
  for(const auto & i : cameraIPList)
  {
    dataList.push_back({i,counter});
    counter++;
  }
  ssp_main=new SSPCollege(dataList,Handle_H264Data);
  std::cout<<"Camera boot finish"<<std::endl;

  counter=0;
  bool startFlag=true;
  signal(SIGINT,Handle_SIGINT);
  while(sleep(10)==0)
  {
    if(startFlag)
    {
      std::cout<<"Camera StartShot "<<counter<<std::endl;
      ssp_main->StartShot();
    }
    else
    {
      std::cout<<"Camera StopShot "<<counter<<std::endl;
      ssp_main->StopShot();
    }
    counter++;
    startFlag=!startFlag;
  }
  
  delete ssp_main;
}
